package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.PeriodicalsExcellent;
import com.company.project.service.PeriodicalsExcellentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* Created by CodeGenerator on 2018/10/10.
*/
@RestController
@RequestMapping("/periodicalsexcellent")
public class PeriodicalsExcellentController {
    @Resource
    private PeriodicalsExcellentService periodicalsExcellentService;

    @PostMapping("/add")
    public Result add(PeriodicalsExcellent periodicalsExcellent) {
        periodicalsExcellentService.save(periodicalsExcellent);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        periodicalsExcellentService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(PeriodicalsExcellent periodicalsExcellent) {
        periodicalsExcellentService.update(periodicalsExcellent);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        PeriodicalsExcellent periodicalsExcellent = periodicalsExcellentService.findById(id);
        return ResultGenerator.genSuccessResult(periodicalsExcellent);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<PeriodicalsExcellent> list = periodicalsExcellentService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
